package com.cx.utils;

import java.util.ArrayList;
import java.util.List;

import org.cx.entity.PageData;

/**
 * 类名称：MenuTreeUtil 类描述：递归构造树型结构
 */
public class MenuTreeUtil {

	public static List<PageData> menuList(List<PageData> menu) {
		List<PageData> list = new ArrayList<PageData>();
		if(menu != null && menu.size() > 0){
			for (PageData pd : menu) {
				Long parentId = (Long) pd.get("parentId");
				if (parentId == 1L) {
					pd.put("menuChild", menuChild((Long) pd.get("id"),menu));
					list.add(pd);
				}
			}
		}
		
		return list;
	}

	public static List<?> menuChild(Long id,List<PageData> menu) {
		List<PageData> list = new ArrayList<PageData>();
		for (PageData pd : menu) {
			if ((Long) pd.get("parentId") == id) {
				pd.put("menuChild", menuChild((Long) pd.get("id"),menu));
				list.add(pd);
			}
		}
		return list;
	}


    public static List<PageData> menuList(List<PageData> menulist, Long id) {
        List<PageData> list = new ArrayList<PageData>();
        if(menulist != null && menulist.size() > 0){
            for (PageData pd : menulist) {
                Long parentId = (Long) pd.get("parentId");
                if (parentId == id) {
                    pd.put("menuChild", menuChild((Long) pd.get("id"),menulist));
                    list.add(pd);
                }
            }
        }

        return list;
    }
}
